<?php
    @include_once("conn.php");

    if(!isset($_GET["key"])){
        $obj = array();
        $obj["status"] = false;
        $obj["msg"] = "请传入完整参数";
        $json = json_encode($obj);
        exit($json);
    }

    $key = $_GET["key"];

    $sql = "select id,name,class,chinese,math,english,chinese+math+english as total from  `grade` where name like '%$key%' ";
    
     // 执行mysql语句
     $result = mysqli_query($conn,$sql);
     // print_r($result);
 
     $obj = array();
     if($result){
 
 
         $list = array();
         // 解析数据  => 赋值给变量 $item  =>  有数据,循环解析  没有数据(null) =>跳出循环
         while($item = mysqli_fetch_assoc($result)){
             // 预处理
             $item["chinese"] = $item["chinese"]*1;
             $item["math"] = $item["math"]*1;
             $item["english"] = $item["english"]*1;
             $item["total"] = $item["total"]*1;
             array_push($list,$item);
         }
 
         // print_r($list);
 
         $obj["status"] = true;
         $obj["msg"] = "OK";
         $obj["list"] = $list;
 
     }else{
         $obj["status"] = false;
         $obj["msg"] = "sql语句有误";
         $obj["sql"] = $sql;
     }
 
     echo json_encode($obj);


?>